package com.zhl.actor;

import akka.actor.ActorSystem;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2018/12/29.
 * spring启动创建ActorSystem,使用时直接注入即可
 */
@Component
public class ActorApplication {

    private static Logger log = LoggerFactory.getLogger(ActorApplication.class);

    public ActorApplication() {
    }

    @Bean
    public ActorSystem actorSystem() {

        try {
            String akkaPath = "akka.conf";
            log.info("加载akka配置,路径:{}",akkaPath);
            Config config = ConfigFactory.load(akkaPath);
            log.info("ActorSystem 初始化...");
            log.info("akka.default-dispatcher 初始化参数 parallelism-min:{}", Integer.valueOf(config.getInt("akka.actor.default-dispatcher.fork-join-executor.parallelism-min")));
            log.info("akka.default-dispatcher 初始化参数 parallelism-factor:{}", Integer.valueOf(config.getInt("akka.actor.default-dispatcher.fork-join-executor.parallelism-factor")));
            log.info("akka.default-dispatcher 初始化参数 parallelism-max:{}", Integer.valueOf(config.getInt("akka.actor.default-dispatcher.fork-join-executor.parallelism-max")));
            ActorSystem actorSystem = ActorSystem.create("sys", config);
            return actorSystem;
        } catch (Exception var4) {
            log.error("ActorSystem 启动失败：", var4);
            return null;
        }
    }

}
